import wx
import pymysql
Sid=0
class MyFrame(wx.Frame):
    gauge = None
    count = 0
    timer = None
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, '宿舍管理系统', size=(400, 300), style=wx.DEFAULT_FRAME_STYLE)
        self.Center()
        # 设置icon图标
        icon = wx.Icon('D:/Python的日常/drom_Manage/py.ico', wx.BITMAP_TYPE_ICO)
        self.SetIcon(icon)

        # 创建面板
        panel = wx.Panel(self)
        panel.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBack)

        #创建进度条
        self.gauge = wx.Gauge(panel, range=100,size=(380, -1))
        # 创建“登陆”、“取消”、“注册”按钮,并绑定事件
        self.bt_login = wx.Button(panel, label='登陆')
        self.Bind(wx.EVT_BUTTON, self.Begin,self.bt_login)
        #计时器 将登陆成功后触发的窗口放到计时器触发之后
        self.timer = wx.Timer(self, id=wx.ID_ANY)
        self.Bind(wx.EVT_TIMER, self.time, self.timer)

        self.bt_login.SetBackgroundColour("#0a74f7")
        self.bt_login.SetForegroundColour("Pink")

        self.bt_cancel = wx.Button(panel, label='取消')
        self.bt_cancel.Bind(wx.EVT_BUTTON, self.OnclickCancel)
        self.bt_cancel.SetBackgroundColour("#0a74f7")
        self.bt_cancel.SetForegroundColour("Pink")

        self.bt_register=wx.Button(panel,label='注册',size=(150,20))
        self.bt_register.Bind(wx.EVT_BUTTON,self.register)
        self.bt_register.SetBackgroundColour("#0a74f7")
        self.bt_register.SetForegroundColour("Pink")

        # 创建文本，左对齐
        self.title = TransparentStaticText(panel, label="宿舍管理系统")
        font = wx.Font(20, wx.DEFAULT, wx.FONTSTYLE_NORMAL, wx.NORMAL, faceName='华文行楷')
        # 把标题的字设置为上面的字体
        self.title.SetFont(font)
        self.label_user = TransparentStaticText(panel, label="用户名:")
        self.text_user = wx.TextCtrl(panel, style=wx.TE_LEFT)
        self.label_pwd = TransparentStaticText(panel, label="密   码:")
        self.text_password = wx.TextCtrl(panel, style=wx.TE_PASSWORD)
        # 添加容器，容器中控件按横向并排排列
        hsizer_user = wx.BoxSizer(wx.HORIZONTAL)
        hsizer_user.Add(self.label_user, proportion=0, flag=wx.ALL, border=8)
        hsizer_user.Add(self.text_user, proportion=1, flag=wx.ALL, border=5)

        hsizer_pwd = wx.BoxSizer(wx.HORIZONTAL)
        hsizer_pwd.Add(self.label_pwd, proportion=0, flag=wx.ALL, border=9)
        hsizer_pwd.Add(self.text_password, proportion=1, flag=wx.ALL, border=5)

        hsizer_button = wx.BoxSizer(wx.HORIZONTAL)
        hsizer_button.Add(self.bt_login, proportion=0, flag=wx.ALIGN_CENTER, border=5)
        hsizer_button.Add(self.bt_cancel, proportion=0, flag=wx.ALIGN_CENTER, border=5)

        hsizer_button1=wx.BoxSizer(wx.HORIZONTAL)
        hsizer_button1.Add(self.bt_register,proportion=0,flag=wx.ALIGN_CENTER,border=5)

        hsizer_gauge=wx.BoxSizer(wx.HORIZONTAL)
        hsizer_gauge.Add(self.gauge,proportion=0,flag=wx.ALIGN_CENTER,border=5)
        # 添加容器，容器中控件按纵向并排排列
        vsizer_all = wx.BoxSizer(wx.VERTICAL)
        vsizer_all.Add(self.title, proportion=0, flag=wx.BOTTOM | wx.TOP | wx.ALIGN_CENTER,border=40)
        vsizer_all.Add(hsizer_user, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=55)
        vsizer_all.Add(hsizer_pwd, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=55)
        vsizer_all.Add(hsizer_button, proportion=0, flag=wx.ALIGN_CENTER | wx.TOP, border=5)
        vsizer_all.Add(hsizer_button1,proportion=0,flag=wx.ALIGN_CENTER| wx.TOP,border=5)
        vsizer_all.Add(hsizer_gauge,proportion=0,flag=wx.ALIGN_CENTER| wx.TOP,border=5)
        panel.SetSizer(vsizer_all)

    def pngSize(self):  # 加载图片函数
        p = wx.Image("D:/Python的日常/drom_Manage/cutegirls.jpg", wx.BITMAP_TYPE_JPEG).ConvertToBitmap()  # 载入图片
        img = p.ConvertToImage()
        bgm = img.Scale(400, 300)
        return wx.Bitmap(bgm)  # 返回 bitmap函数值

    def OnEraseBack(self, event):  # 设置画布背景函数
        dc = event.GetDC()
        if not dc:
            dc = wx.ClientDC(self)
            rect = self.GetUpdateRegion().GetBox()
            dc.SetClippingRect(rect)
        dc.Clear()
        dc.DrawBitmap(self.pngSize(), 0, 0)

    def OnclickCancel(self, event):
        """ 点击取消按钮，执行方法 """
        # 清空输入的用户名
        self.text_user.SetValue("")
        # 清空输入的密码
        self.text_password.SetValue("")

    def register(self,event):
        self.Destroy()
        frame=Frame_register(parent=None,id=-1)
        frame.Show()
    #启动计时器
    def Begin(self,event):
        #启动
        self.timer.Start(1)
    #进度触发事件
    def time(self,event):
        self.count=self.count+1
        self.gauge.SetValue(self.count)
        if self.count==100:
            self.timer.Stop()
            self.Login()
            print("任务已完成")
    def Login(self):
        db = pymysql.connect(host='localhost', user='root', password='root', database='drom_student')
        cursor = db.cursor()
        # 获取界面密码以及学号
        global Sid
        Sid = self.text_user.GetValue()
        password = self.text_password.GetValue()
        sql="select password from student_information where Sid='%d'"%int(Sid)
        cursor.execute(sql)
        result=cursor.fetchone()
        db.close()
        if result:
            if result[0]==password:
                self.Destroy()
                #登陆成功
                frame=Frame_Login(parent=None,id=-1)
                frame.Show()
            else:
                wx.MessageBox("账号密码错误！")
                self.Destroy()
        else:
            wx.MessageBox("账号不存在!")
            self.Destroy()
    def GetSid(self):
        return self.text_user.GetValue()


#控件透明化 重写StaticText 控件
class TransparentStaticText(wx.StaticText):
    """
    重写StaticText控件
    """
    def __init__(self, parent, id=wx.ID_ANY, label='', pos=wx.DefaultPosition, size=wx.DefaultSize,
                 style=wx.TRANSPARENT_WINDOW, name='TransparentStaticText'):
        wx.StaticText.__init__(self, parent, id, label, pos, size, style, name)
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_ERASE_BACKGROUND, lambda event: None)
        self.Bind(wx.EVT_SIZE, self.OnSize)
    def OnPaint(self, event):
        bdc = wx.PaintDC(self)
        dc = wx.GCDC(bdc)
        font_face = self.GetFont()
        font_color = self.GetForegroundColour()
        dc.SetFont(font_face)
        dc.SetTextForeground(font_color)
        dc.DrawText(self.GetLabel(), 0, 0)

    def OnSize(self, event):
        self.Refresh()
        event.Skip()

#注册窗口
class Frame_register(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, '宿舍管理系统', size=(400, 300), style=wx.DEFAULT_FRAME_STYLE)
        self.Center()
        # 设置icon图标
        icon = wx.Icon('D:/Python的日常/drom_Manage/py.ico', wx.BITMAP_TYPE_ICO)
        self.SetIcon(icon)
        # 创建面板
        panel = wx.Panel(self)
        panel.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBack)

        #确定button
        self.bt_sure = wx.Button(panel, label='确认')
        self.bt_sure.Bind(wx.EVT_BUTTON, self.OnclickSubmit)
        self.bt_sure.SetBackgroundColour("#0a74f7")
        self.bt_sure.SetForegroundColour("Pink")
        # 创建文本，左对齐
        self.title = TransparentStaticText(panel, label="注册")
        font = wx.Font(20, wx.DEFAULT, wx.FONTSTYLE_NORMAL, wx.NORMAL, faceName='华文行楷')
        # 把标题的字设置为上面的字体
        self.title.SetFont(font)
        self.label_pwd = TransparentStaticText(panel, label="密   码:")
        self.text_password = wx.TextCtrl(panel, style=wx.TE_PASSWORD)

        self.label_pwd1 = TransparentStaticText(panel, label="确认密码:")
        self.text_password1 = wx.TextCtrl(panel, style=wx.TE_PASSWORD)

        self.label_Did=TransparentStaticText(panel, label="寝室号:")
        self.text_Did=wx.TextCtrl(panel,style=wx.TE_LEFT)

        # 添加容器，容器中控件按横向并排排列
        hsizer_pwd = wx.BoxSizer(wx.HORIZONTAL)
        hsizer_pwd.Add(self.label_pwd, proportion=0, flag=wx.ALL, border=9)
        hsizer_pwd.Add(self.text_password, proportion=1, flag=wx.ALL, border=5)

        hsizer_pwd1=wx.BoxSizer(wx.HORIZONTAL)
        hsizer_pwd1.Add(self.label_pwd1,proportion=0,flag=wx.ALL,border=9)
        hsizer_pwd1.Add(self.text_password1,proportion=1,flag=wx.ALL,border=5)

        hsizer_Did=wx.BoxSizer(wx.HORIZONTAL)
        hsizer_Did.Add(self.label_Did,proportion=0,flag=wx.ALL,border=9)
        hsizer_Did.Add(self.text_Did,proportion=0,flag=wx.ALL,border=5)

        hsizer_button = wx.BoxSizer(wx.HORIZONTAL)
        hsizer_button.Add(self.bt_sure, proportion=0, flag=wx.ALIGN_CENTER, border=5)

        # 添加容器，容器中控件按纵向并排排列
        vsizer_all = wx.BoxSizer(wx.VERTICAL)
        vsizer_all.Add(self.title, proportion=0, flag=wx.BOTTOM | wx.TOP | wx.ALIGN_CENTER,border=20)
        vsizer_all.Add(hsizer_pwd, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=55)
        vsizer_all.Add(hsizer_pwd1,proportion=0,flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=55)
        vsizer_all.Add(hsizer_Did,proportion=0,flag=wx.EXPAND | wx.LEFT | wx.RIGHT,border=55)
        vsizer_all.Add(hsizer_button, proportion=0, flag=wx.ALIGN_CENTER | wx.TOP, border=5)
        panel.SetSizer(vsizer_all)

    def pngSize(self):  # 加载图片函数
        p = wx.Image("D:/Python的日常/drom_Manage/cuteshabi.jpg", wx.BITMAP_TYPE_JPEG).ConvertToBitmap()  # 载入图片
        img = p.ConvertToImage()
        bgm = img.Scale(400, 300)
        return wx.Bitmap(bgm)  # 返回 bitmap函数值
    def OnEraseBack(self, event):  # 设置画布背景函数
        dc = event.GetDC()
        if not dc:
            dc = wx.ClientDC(self)
            rect = self.GetUpdateRegion().GetBox()
            dc.SetClippingRect(rect)
        dc.Clear()
        dc.DrawBitmap(self.pngSize(), 0, 0)

    def OnclickSubmit(self,event):
        db = pymysql.connect(host='localhost', user='root', password='root', database='drom_student')
        cursor = db.cursor()
        #获取界面密码以及寝室号
        password=self.text_password.GetValue()
        password1=self.text_password1.GetValue()
        Did=self.text_Did.GetValue()
        flag = 0
        if password == '':
            wx.MessageBox("密码不可以为空！")
            flag = 1
        elif password1 == '':
            wx.MessageBox("请确认密码！")
            flag = 1
        if flag == 0:
            if password == password1:
                if Did=='':
                    wx.MessageBox("请输入寝室号！")
                elif int(Did)>100 and int(Did)<706:
                    #插入密码与寝室号
                    sql = "insert into student_information(Did,password) values('%d','%s')" % (int(Did), password)
                    cursor.execute(sql)
                    db.commit()
                    #查询当前插入时的Id
                    sql="select Id from student_information where Id=(select max(id) from student_information)"
                    cursor.execute(sql)
                    IId=cursor.fetchone()
                    #根据Id去查找 学号Sid
                    sql="select Sid from student_information where Id='%d';"%IId
                    cursor.execute(sql)
                    result=cursor.fetchone()
                    db.commit()
                    db.close()
                    #将Sid显示在消息窗口上
                    wx.MessageBox("注册成功！你的账号即学号是：%d"%result)
                    self.Destroy()
                    myframe = MyFrame(parent=None, id=-1)
                    myframe.Show()
                else:
                    wx.MessageBox("寝室号不存在，请重新输入！")
            else:
                wx.MessageBox("确认密码错误！")

#登陆窗口
class Frame_Login(wx.Frame) :
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, '宿舍管理系统', size=(600, 400), style=wx.DEFAULT_FRAME_STYLE)
        self.Center()
        # 设置icon图标
        icon = wx.Icon('D:/Python的日常/drom_Manage/py.ico', wx.BITMAP_TYPE_ICO)
        self.SetIcon(icon)
        #创建面板设置背景图片
        panel = wx.Panel(self)
        panel.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBack)
        #创建菜单
        menu_bar = wx.MenuBar()
        # 新建"宿舍基本情况"菜单
        file_menu = wx.Menu()
        file_menu.Append(wx.ID_NEW, "查询宿舍成员")
        file_menu.AppendSeparator()  # 添加分割线
        file_menu.Append(wx.ID_OPEN, "查询电费")
        file_menu.AppendSeparator()  # 添加分割线
        file_menu.Append(wx.ID_SAVE,"查询水费")
        #通过id绑定事件 id只可以采用wx里面定义的id
        self.Bind(wx.EVT_MENU, self.select_member, id=wx.ID_NEW)
        self.Bind(wx.EVT_MENU, self.select_eletric, id=wx.ID_OPEN)
        self.Bind(wx.EVT_MENU, self.select_water, id=wx.ID_SAVE)
        #添加菜单到目标栏
        menu_bar.Append(file_menu, "宿舍基本情况")  # 添加到菜单栏

        #添加缴费服务
        pay_menu = wx.Menu()
        pay_menu.Append(wx.ID_COPY, "充值电费")
        pay_menu.AppendSeparator()  # 添加分割线
        pay_menu.Append(wx.ID_PASTE, "充值水费")
        pay_menu.AppendSeparator()  # 添加分割线
        # 通过id绑定事件 id只可以采用wx里面定义的id
        self.Bind(wx.EVT_MENU, self.recharge_eletric, id=wx.ID_COPY)
        self.Bind(wx.EVT_MENU, self.recharge_water, id=wx.ID_PASTE)
        #添加缴费进目标栏
        menu_bar.Append(pay_menu, "缴费服务")  # 添加到菜单栏

        #添加报修服务
        fix_menu = wx.Menu()
        fix_menu.Append(wx.ID_CLEAR, "立即报修")
        fix_menu.AppendSeparator()  # 添加分割线
        self.Bind(wx.EVT_MENU, self.fix, id=wx.ID_CLEAR)
        # 添加报修进目标栏
        menu_bar.Append(fix_menu, "保修")  # 添加到菜单栏

        #添加设置
        setup_menu=wx.Menu()
        setup_menu.Append(wx.ID_FIND, "修改密码")
        setup_menu.AppendSeparator()  # 添加分割线
        setup_menu.Append(wx.ID_DELETE, "注销")
        setup_menu.AppendSeparator()  # 添加分割线
        setup_menu.Append(wx.ID_CUT, "退出")
        setup_menu.AppendSeparator()  # 添加分割线

        self.Bind(wx.EVT_MENU, self.modify_psd, id=wx.ID_FIND)
        self.Bind(wx.EVT_MENU, self.Delete_data, id=wx.ID_DELETE)
        self.Bind(wx.EVT_MENU, self.close, id=wx.ID_CUT)
        # 添加设置进目标栏
        menu_bar.Append(setup_menu, "设置")  # 添加到菜单栏
        #将菜单栏显示到窗口
        self.SetMenuBar(menu_bar)

    def pngSize(self):  # 加载图片函数
        p = wx.Image("D:/Python的日常/drom_Manage/cutebiantai.jpg", wx.BITMAP_TYPE_JPEG).ConvertToBitmap()  # 载入图片
        img = p.ConvertToImage()
        bgm = img.Scale(600, 400)
        return wx.Bitmap(bgm)  # 返回 bitmap函数值

    def OnEraseBack(self,event):  # 设置画布背景函数
        dc = event.GetDC()
        if not dc:
            dc = wx.ClientDC(self)
            rect = self.GetUpdateRegion().GetBox()
            dc.SetClippingRect(rect)
        dc.Clear()
        dc.DrawBitmap(self.pngSize(), 0, 0)

    def select_member(self,event):

        db = pymysql.connect(host='localhost', user='root', password='root', database='drom_student')
        cursor = db.cursor()
        # 根据Sid去查找 宿舍号Did
        print(Sid)
        sql = "select Did from student_information where Sid='%d';" % int(Sid)
        cursor.execute(sql)
        result = cursor.fetchone()
        db.commit()
        print(result[0])
        #根据Did去查询学号
        sql="select Sid from student_information where Did='%d'"%int(result[0])
        print(sql)
        cursor.execute(sql)
        result=cursor.fetchall()
        db.commit()
        db.close()
        print(result)
        for i in result:
            wx.MessageBox(str(i[0]))
        '''
        # 将Did显示在消息窗口上
        wx.MessageBox("%d" % result)
        #创建窗口
        frame=Frame_select_member(parent=None,id=-1)
        frame.Show()
        wx.MessageBox("功能暂未开放！")
        '''

    def select_eletric(self,event):
        db = pymysql.connect(host='localhost', user='root', password='root', database='drom_student')
        cursor = db.cursor()
        # 根据Sid去查找 宿舍号Did
        print(Sid)
        sql = "select Did from student_information where Sid='%d';" % int(Sid)
        cursor.execute(sql)
        result = cursor.fetchone()
        db.commit()
        print(result[0])

        # 根据Did去查找电费
        sql = "select electric from drom_information where Did='%d';" % result[0]
        cursor.execute(sql)
        result = cursor.fetchone()
        db.commit()
        db.close()
        wx.MessageBox("电费：%s" % result[0])


    def select_water(self,event):
        db = pymysql.connect(host='localhost', user='root', password='root', database='drom_student')
        cursor = db.cursor()
        # 根据Sid去查找 宿舍号Did
        print(Sid)
        sql = "select Did from student_information where Sid='%d';" % int(Sid)
        cursor.execute(sql)
        result = cursor.fetchone()
        db.commit()
        print(result[0])

        # 根据Did去查找电费
        sql = "select water from drom_information where Did='%d';" % result[0]
        cursor.execute(sql)
        result = cursor.fetchone()
        db.commit()
        db.close()
        wx.MessageBox("水费：%s" % result[0])

    def recharge_eletric(self,event):
        # 创建窗口
        frame = Frame_recharge_eletric(parent=None, id=-1)
        frame.Show()
    def recharge_water(self,event):
        # 创建窗口
        frame = Frame_recharge_water(parent=None, id=-1)
        frame.Show()
    def fix(self,event):
        # 创建窗口
        frame = Frame_fix(parent=None, id=-1)
        frame.Show()

    def modify_psd(self,event):
        # 创建窗口
        frame = Frame_modify(parent=None, id=-1)
        frame.Show()
    def Delete_data(self,event):
        wx.MessageBox("你的行为比较危险！不建议点击")
    def close(self,event):
        self.Close()

'''
#查询宿舍成员的窗口
class Frame_select_member(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, '宿舍管理系统', size=(300, 200), style=wx.DEFAULT_FRAME_STYLE)
        self.Center()
        panel = wx.Panel(self)
        self.label_user = TransparentStaticText(panel, label="请输入寝室号:")
        self.text_user = wx.TextCtrl(panel, style=wx.TE_LEFT)
        #创建按钮
        self.bt_login = wx.Button(panel, label='确认')
        self.Bind(wx.EVT_BUTTON, self.Sure, self.bt_login)

        #布局
        hsizer_user = wx.BoxSizer(wx.HORIZONTAL)
        hsizer_user.Add(self.label_user, proportion=0, flag=wx.ALL, border=8)
        hsizer_user.Add(self.text_user, proportion=1, flag=wx.ALL, border=5)

        hsizer_button = wx.BoxSizer(wx.HORIZONTAL)
        hsizer_button.Add(self.bt_login, proportion=0, flag=wx.ALIGN_CENTER, border=5)

        vsizer_all = wx.BoxSizer(wx.VERTICAL)
        vsizer_all.Add(hsizer_user, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=55)
        vsizer_all.Add(hsizer_button, proportion=0, flag=wx.ALIGN_CENTER| wx.TOP, border=5)
        panel.SetSizer(vsizer_all)

    def Sure(self,event):
        Did=self.text_user.GetValue()
        db = pymysql.connect(host='localhost', user='root', password='root', database='drom_student')
        cursor = db.cursor()
        # 根据Did去查找 学号Sid
        sql = "select Sid from student_information where Did='%d';" % int(Did)
        cursor.execute(sql)
        result = cursor.fetchall()
        db.commit()
        db.close()
        # 将Did显示在消息窗口上
        for i in result:
            for j in range(0,4):
                wx.MessageBox(i[j])
'''
#充值电费 （弹出二维码？）
class Frame_recharge_eletric(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, '宿舍管理系统', size=(300, 200), style=wx.DEFAULT_FRAME_STYLE)
        self.Center()
        panel = wx.Panel(self)

        self.label_user1 = TransparentStaticText(panel, label="请输入充值金额:")
        self.text_user1 = wx.TextCtrl(panel, style=wx.TE_LEFT)
        #创建按钮
        self.bt_login = wx.Button(panel, label='确认')
        self.Bind(wx.EVT_BUTTON, self.Sure, self.bt_login)

        #布局
        hsizer_user = wx.BoxSizer(wx.HORIZONTAL)
        hsizer_user1 = wx.BoxSizer(wx.HORIZONTAL)
        hsizer_user1.Add(self.label_user1, proportion=0, flag=wx.ALL, border=8)
        hsizer_user1.Add(self.text_user1, proportion=1, flag=wx.ALL, border=5)

        hsizer_button = wx.BoxSizer(wx.HORIZONTAL)
        hsizer_button.Add(self.bt_login, proportion=0, flag=wx.ALIGN_CENTER, border=5)

        vsizer_all = wx.BoxSizer(wx.VERTICAL)
        vsizer_all.Add(hsizer_user1, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=55)
        vsizer_all.Add(hsizer_button, proportion=0, flag=wx.ALIGN_CENTER| wx.TOP, border=5)
        panel.SetSizer(vsizer_all)

    def Sure(self,event):
        Money=self.text_user1.GetValue()
        db = pymysql.connect(host='localhost', user='root', password='root', database='drom_student')
        cursor = db.cursor()
        '''
        条件插入语句不明白
        sql = "insert into drom_information(Sid,electric) select '%d','%s'"where ？ % (Did, Money)
        '''
        # 根据Sid去查找 宿舍号Did
        sql = "select Did from student_information where Sid='%d';" % int(Sid)
        cursor.execute(sql)
        result = cursor.fetchone()
        db.commit()
        print(result[0])
        #更新表
        sql="update drom_information set electric='%s' where Did='%d';"%(Money,result[0])
        cursor.execute(sql)
        db.commit()
        db.close()
        wx.MessageBox("充值成功！")

#充值水费
class Frame_recharge_water(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, '宿舍管理系统', size=(300, 200), style=wx.DEFAULT_FRAME_STYLE)
        self.Center()
        panel = wx.Panel(self)


        self.label_user1 = TransparentStaticText(panel, label="请输入充值金额:")
        self.text_user1 = wx.TextCtrl(panel, style=wx.TE_LEFT)
        #创建按钮
        self.bt_login = wx.Button(panel, label='确认')
        self.Bind(wx.EVT_BUTTON, self.Sure, self.bt_login)

        #布局

        hsizer_user1 = wx.BoxSizer(wx.HORIZONTAL)
        hsizer_user1.Add(self.label_user1, proportion=0, flag=wx.ALL, border=8)
        hsizer_user1.Add(self.text_user1, proportion=1, flag=wx.ALL, border=5)

        hsizer_button = wx.BoxSizer(wx.HORIZONTAL)
        hsizer_button.Add(self.bt_login, proportion=0, flag=wx.ALIGN_CENTER, border=5)

        vsizer_all = wx.BoxSizer(wx.VERTICAL)
        vsizer_all.Add(hsizer_user1, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=55)
        vsizer_all.Add(hsizer_button, proportion=0, flag=wx.ALIGN_CENTER| wx.TOP, border=5)
        panel.SetSizer(vsizer_all)
    def Sure(self,event):
        Money=self.text_user1.GetValue()
        db = pymysql.connect(host='localhost', user='root', password='root', database='drom_student')
        cursor = db.cursor()
        '''
        条件插入语句不明白
        sql = "insert into drom_information(Sid,electric) select '%d','%s'"where ？ % (Did, Money)
        '''
        # 根据Sid去查找 宿舍号Did
        sql = "select Did from student_information where Sid='%d';" % int(Sid)
        cursor.execute(sql)
        result = cursor.fetchone()
        db.commit()
        print(result[0])
        #更新表
        sql="update drom_information set water='%s' where Did='%d';"%(Money,result[0])
        cursor.execute(sql)
        db.commit()
        db.close()
        wx.MessageBox("充值成功！")

#报修
class Frame_fix(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, '宿舍管理系统', size=(600, 400), style=wx.DEFAULT_FRAME_STYLE)
        self.Center()
        panel = wx.Panel(self)
        self.label_user1 = TransparentStaticText(panel, label="请输入报修情况:")
        self.text_user1 = wx.TextCtrl(panel, style=wx.TE_LEFT,size=(400,200))
        #创建按钮
        self.bt_login = wx.Button(panel, label='确认')
        self.Bind(wx.EVT_BUTTON, self.Sure, self.bt_login)
        #布局
        hsizer_user1=wx.BoxSizer(wx.HORIZONTAL)
        hsizer_user1.Add(self.label_user1, proportion=0, flag=wx.ALL, border=8)
        hsizer_user1.Add(self.text_user1, proportion=1, flag=wx.ALL, border=5)

        hsizer_button = wx.BoxSizer(wx.HORIZONTAL)
        hsizer_button.Add(self.bt_login, proportion=0, flag=wx.ALIGN_CENTER, border=5)

        vsizer_all = wx.BoxSizer(wx.VERTICAL)
        vsizer_all.Add(hsizer_user1, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=55)
        vsizer_all.Add(hsizer_button, proportion=0, flag=wx.ALIGN_CENTER| wx.TOP, border=5)
        panel.SetSizer(vsizer_all)

    def Sure(self,event):
        text=self.text_user1.GetValue()
        db = pymysql.connect(host='localhost', user='root', password='root', database='drom_student')
        cursor = db.cursor()
        # 根据Sid去查找 宿舍号Did
        print(Sid)
        sql = "select Did from student_information where Sid='%d';" % int(Sid)
        cursor.execute(sql)
        result = cursor.fetchone()
        db.commit()
        print(result[0])
        # 给Fix_information插入数据
        sql = "update drom_information set Fix_information='%s' where Did='%d';"%(text,result[0])
        cursor.execute(sql)
        db.commit()
        db.close()
        wx.MessageBox("报修成功！请等待工作人员维修")

#修改密码ghh
class Frame_modify(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, '宿舍管理系统', size=(300, 200), style=wx.DEFAULT_FRAME_STYLE)
        self.Center()
        panel = wx.Panel(self)


        self.label_user1 = TransparentStaticText(panel, label="请输入修改的密码:")
        self.text_user1 = wx.TextCtrl(panel, style=wx.TE_LEFT)
        #创建按钮
        self.bt_login = wx.Button(panel, label='确认')
        self.Bind(wx.EVT_BUTTON, self.Sure, self.bt_login)

        #布局
        hsizer_user1 = wx.BoxSizer(wx.HORIZONTAL)
        hsizer_user1.Add(self.label_user1, proportion=0, flag=wx.ALL, border=8)
        hsizer_user1.Add(self.text_user1, proportion=1, flag=wx.ALL, border=5)

        hsizer_button = wx.BoxSizer(wx.HORIZONTAL)
        hsizer_button.Add(self.bt_login, proportion=0, flag=wx.ALIGN_CENTER, border=5)

        vsizer_all = wx.BoxSizer(wx.VERTICAL)
        vsizer_all.Add(hsizer_user1, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=55)
        vsizer_all.Add(hsizer_button, proportion=0, flag=wx.ALIGN_CENTER| wx.TOP, border=5)
        panel.SetSizer(vsizer_all)

    def Sure(self,event):
        password=self.text_user1.GetValue()
        db = pymysql.connect(host='localhost', user='root', password='root', database='drom_student')
        cursor = db.cursor()
        '''
        条件插入语句不明白
        sql = "insert into drom_information(Sid,electric) select '%d','%s'"where ？ % (Did, Money)
        '''
        #更新表
        sql="update student_information set password='%s' where Sid='%d';"%(password,int(Sid))
        cursor.execute(sql)
        db.commit()
        db.close()
        wx.MessageBox("修改成功！")

if __name__ == '__main__':
    app = wx.App()  # 初始化
    frame = MyFrame(parent=None, id=-1)  # 实例MyFrame类，并传递参数
    frame.Show()  # 显示窗口
    app.MainLoop()  # 调用主循环方法


